package myJs.admin.limitManage

import myJs.api.Api
import myJs.myPkg._
import myJs.myPkg.yup._

import scala.collection.mutable
import scala.concurrent.Future
import scala.scalajs.js
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.pojo.Pojo.{EmailData, Login, PhoneData, UserNameData}

import scala.scalajs.js.Date
import scala.scalajs.js.JSConverters._

/**
 * Created by yz on 7/12/2022
 */
object ModifyLimitSchema {

  def dateTimeValidateF = (value: Date, orginalValue: String) => {
    val curV = Moment(orginalValue, format = "YYYY-MM-DD H:m:s", strict = true)
    if (orginalValue == "") {
      new Date()
    } else if (curV.isValid()) {
      curV.toDate()
    } else new Date("")
  }

  val schema = Yup.`object`().shape(js.Dictionary(
    "remainTimes" -> Yup.number()
      .integer("有效次数必须为整数！")
      .typeError("有效次数必须为整数！"),
//    "startTime" -> Yup.date()
//      .transform(dateTimeValidateF)
//      .typeError("开始日期不合法！"),
//    "endTime" -> Yup.date()
//      .transform(dateTimeValidateF)
//      .typeError("截止日期不合法！")
  ))
}
